#ifndef _CROSSENGINE_CROSSEVENT_H_
#define _CROSSENGINE_CROSSEVENT_H_
#include "memalloc.h"
#include "list.h"
#include "portable.h"

class CrossObject;

class AbstractCrossEvent
{
public:
    virtual ~AbstractCrossEvent(){}
    AbstractCrossEvent(){_code=0;}
    void SetCode(uint64 code){_code=code;}
    uint64 Code(){return _code;}
    virtual void Invoke(CrossObject* obj)=0;
    DEFINE_OWN_MEM_OPERATION
private:
    uint64 _code;
};

class CrossEvent:public AbstractCrossEvent
{
public:
    CrossEvent(){INIT_LIST_HEAD(&_lst);}

    inline void Enqueue(list_head* head);
    static inline CrossEvent* Entry(list_head* pos);
private:
    list_head _lst;
};

class DelayCrossEvent:public AbstractCrossEvent
{
public:
    DelayCrossEvent(){_deltaTick=0;_forever=false;}
    void SetDeltaTick(uint32 deltaTick){_deltaTick=deltaTick;}
    uint32 DeltaTick(){return _deltaTick;}
    void SetForever(bool forever){_forever=forever;}
    bool IsForever(){return _forever;}
private:
    uint32 _deltaTick;
    bool _forever;
};

#endif//_CROSSENGINE_CROSSEVENT_H_
